﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Text.RegularExpressions;
using System.Windows.Controls;

using MissedMemo.MeatAndCheeseDisc.OrderEntryDataAccess;


namespace MissedMemo.MeatAndCheeseDisc.OrderEntry
{
    public class validateRegExpression : ValidationRule
    {
        public string FormatId { get; set; }


        public override ValidationResult Validate( object value, System.Globalization.CultureInfo cultureInfo )
        {
            RegExFormatAndSample fs = LookupRegularExpression.GetFormatAndExample( FormatId );

            if( !Regex.IsMatch( (string)value, fs.Format ) )
            {
                string strMsg = string.Format( "Please use a valid format (such as '{0}')", fs.Example );
                return new ValidationResult( false, strMsg );
            }

            return ValidationResult.ValidResult;
        }
    }
}
